﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XSTDZ.ERP.Core.Generator;
using XSTDZ.ERP.Core.Extentions;

namespace XSTDZ.ERP.Domain.Models
{
    /// <summary>
    /// 盘点
    /// </summary>
    public partial class ProductReturnBill
    {
        public ProductReturnBill()
        {
            this.ProductReturnBillDetail = new HashSet<ProductReturnBillDetail>();
        }

        public ProductReturnBill InitProductReturnBill()
        {
            if (this.Id == null || this.Id.Equals(Guid.Empty))
            {
                this.Id = (Guid)new SequentialIdentityGenerator().Next;
            }
            this.CreateTime = DateTime.Now;
            this.Deleted = 0;

            return this;
        }
        public ProductReturnBill AddDetails(IEnumerable<ProductReturnBillDetail> details)
        {
            details.Each(d => AddDetails(d));
            return this;
        }
        public ProductReturnBill AddDetails(ProductReturnBillDetail detail)
        {
            if (!this.ProductReturnBillDetail.Contains(detail))
            {
                if (detail.ProductReturnBillID == null || detail.ProductReturnBillID.Equals(Guid.Empty))
                {
                    detail.ProductReturnBillID = this.Id;
                }
                this.ProductReturnBillDetail.Add(detail.InitProductReturnBillDetail());
            }
            return this;
        }
    }
}
